﻿#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.Runtime.dll"

#load "Client.fs"

open Client
open Microsoft.SharePoint.Client
open Microsoft.SharePoint.Client.Application
open System.Security;
open System.Net
open System

// =======================================================
// Work with lists
// =======================================================

let web = Client.Context.Web
Client.Load web
Client.Context.Web.Title

let lists = web.Lists
Client.Load lists
lists.Count

let list = Client.Context.Web.Lists.GetByTitle("Documents")
Client.Load list

list.BaseTemplate

// Work with "property bag" of the lists rootfolder
Client.Load list.RootFolder
Client.Load list.RootFolder.Properties

// Update list
list.Hidden <- true
list.Update()
Client.ExecuteQuery()

// Create a custom access request list
let newListInfo = new ListCreationInformation();
newListInfo.Title <- "Access Requests"
newListInfo.TemplateType <- 160
newListInfo.TemplateFeatureId <- Guid.NewGuid()
newListInfo.QuickLaunchOption <- QuickLaunchOptions.On
let accesslist = Client.Context.Web.Lists.Add(newListInfo)
web.Update()
Client.ExecuteQuery()

// Modify default view
let spView = list.DefaultView
Client.Load spView
spView.ViewFields.Add("CheckoutUser");
spView.Update()
Client.ExecuteQuery()

// Delete List
let delList = Client.Context.Web.Lists.GetByTitle("Documents")
Client.Load delList
delList.DeleteObject()
Client.ExecuteQuery()


